package com.example.weektwo.async03;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.weektwo.R;
import com.example.weektwo.async02.VideoInfo;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;
import de.hdodenhof.circleimageview.CircleImageView;

public class ShowVideoAdapter extends BaseAdapter {
    private static final String TAG = "VideoAdapter";
    Context context;
    List<VideoInfo.ItemListBean> itemList;

    public ShowVideoAdapter(Context context, List<VideoInfo.ItemListBean> itemList) {
        this.context = context;
        this.itemList = itemList;
    }

    @Override
    public int getCount() {
        return itemList.size();
    }

    @Override
    public Object getItem(int position) {
        return itemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.item_voidplayer_list02,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        VideoInfo.ItemListBean.DataBean itemListBean = itemList.get(position).getData();
        String title = itemListBean.getTitle();
        String picUrl = itemListBean.getCover().getFeed();
       holder.jzvd.setUp(itemListBean.getPlayUrl(),title, Jzvd.SCREEN_NORMAL);
       Picasso.with(context).load(picUrl).into(holder.jzvd.posterImageView);
       holder.jzvd.positionInList=position;
//      作者图片
        VideoInfo.ItemListBean.DataBean.ProviderBean provider = itemListBean.getProvider();
        holder.authorTv.setText(provider.getName());
        String iconUrl = provider.getIcon();
        if (!TextUtils.isEmpty(iconUrl)) {
            Picasso.with(context).load(iconUrl).into(holder.authorIv);
        }

//      喜好
        VideoInfo.ItemListBean.DataBean.ConsumptionBean consumption = itemListBean.getConsumption();
        holder.likeTv.setText(String.valueOf(consumption.getCollectionCount()));
        holder.pinglunTv.setText(String.valueOf(consumption.getReplyCount()));

        return convertView;
    }
    class ViewHolder{
        TextView authorTv,likeTv,pinglunTv;
        JzvdStd jzvd;
        CircleImageView authorIv;
        public ViewHolder(View view){
            authorIv=view.findViewById(R.id.item_video_iv_author);
            authorTv=view.findViewById(R.id.item_video_tv_author);
            jzvd = view.findViewById(R.id.item_video_jzvd);
            likeTv=view.findViewById(R.id.item_video_tv_like);
            pinglunTv=view.findViewById(R.id.item_video_tv_pinglun);
        }
    }
}
